﻿using com.iot.core.infrastructure;
using com.iot.ht.Controllers.htsoft.service;
using com.iot.ht.Controllers.httask.service;
using System.Reflection;

namespace com.iot.ht.boot
{
    public class HtStartup : INopStartup
    {
        public int Order => 20;

        public void Configure(IApplicationBuilder application)
        {
              
        }

        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            services.AddCaptcha(configuration);

            var typeFinder = Singleton<ITypeFinder>.Instance; 
            var startupConfigurations = typeFinder.FindClassesOfType<IHTService>();
            foreach (var m in startupConfigurations)
            { 
                var iname = m.FullName.Replace(m.Name, "") + "I" + m.Name;
                var it = typeof(HtStartup).GetTypeInfo().Assembly.GetType(iname);                 
                if (it != null)
                { 
                    var descriptor = new ServiceDescriptor(it, m, ServiceLifetime.Scoped);
                    services.Add(descriptor); 
                } 
            }
           services.AddHostedService<HtSoftService>();
           services.AddHostedService<HtTaskService>();

        }
    }
}
